package com.livepan.server.utils;

import com.livepan.server.service.ProblemService;
import com.livepan.server.service.UserService;
import com.livepan.server.service.model.ProblemModel;
import com.livepan.server.service.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

public class ModelUtil {
    @Autowired
    private static UserService userService;
    private static Map<String, UserModel> userModelMap;
    @Autowired
    private static ProblemService problemService;
    private static Map<Integer, ProblemModel> problemModelMap;

    private static Map<String, List<ProblemModel>> problemListMap;

    public static UserModel getUserModelFromUserMap(String userId) {
        if (userModelMap.get(userId) != null) {
            return userModelMap.get(userId);
        }
        UserModel userModel = userService.getUserById(userId);
        userModelMap.put(userId, userModel);
        return userModel;
    }


    public static ProblemModel getProblemModelFromProblemMap(Integer problemId) {
        if (problemModelMap.get(problemId) != null) {
            return problemModelMap.get(problemId);
        }
        ProblemModel problemModel = problemService.getProblemByID(problemId);
        problemModelMap.put(problemId, problemModel);
        return problemModel;
    }


}
